#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
| Created on 2020/6/22 9:04

| @author: aimee.mei
"""

import sys, logging,traceback
from util.db_util import execute_query
from  proj_spec.industrial_chain.get_tree_id import get_sam_product_tree_id


def get_client_tree_view_type(name):
    '''
    查询精选产业链视图查看方式
    | 1：左右结构
    | 2：上下结构

    :param name: 精选产业链name

    :return: view_type
    '''

    try:
        results = execute_query(
            "select view_type from scm_product_tree where name = '%s' and status !=0" % name)
        result = results[0][0]
        return result
    except Exception as e:
        logging.exception("Retrieve latest id failed!")
        logging.error(e)
        traceback.print_exc()
        return None


def get_client_productCode(name):
    '''
    获取产品的productcode

    :param name: 产品名称

    :return: code
    '''
    try:
        results = execute_query(
            "SELECT code FROM scm_product where tree_id='%s' and level=1 and name_zh='%s'; " % (get_sam_product_tree_id('test_测试_data_update'),name))
        result = results[0][0]
        return result
    except Exception as e:
        logging.exception("Retrieve latest id failed!")
        logging.error(e)
        traceback.print_exc()
        return None


